package cc.chinagps.gateway.unit.eg.upload.cmds;

import cc.chinagps.gateway.client.TransferDeviceManager;
import cc.chinagps.gateway.client.UnitClient;
import cc.chinagps.gateway.client.UnitClientManager;
import cc.chinagps.gateway.client.bean.DeviceInfo;
import cc.chinagps.gateway.client.session.ISession;
import cc.chinagps.gateway.unit.beans.UnitInfo;
import org.apache.log4j.Logger;

import cc.chinagps.gateway.log.LogManager;
import cc.chinagps.gateway.unit.UnitServer;
import cc.chinagps.gateway.unit.UnitSocketSession;
import cc.chinagps.gateway.unit.beans.Loginout;
import cc.chinagps.gateway.unit.common.UploadUtil;
import cc.chinagps.gateway.unit.eg.pkg.EGPackage;
import cc.chinagps.gateway.unit.eg.util.EGTimeFormatUtil;

public class Cmd04 extends CheckLoginHandler {
	private Logger logger_debug = Logger.getLogger(LogManager.LOGGER_NAME_DEBUG);

	@Override
	public boolean handlerPackageSessionChecked(EGPackage pkg, UnitServer server, UnitSocketSession session)
			throws Exception {
        String callLetter = session.getUnitInfo().getCallLetter();
		Loginout loginout = new Loginout();
        loginout.setIsLogin(Loginout.LOGOUT);
        loginout.setLoginTime(session.getLoginTime());

        String collectTime = EGTimeFormatUtil.getDateTime(pkg.getData(), 0, 6);
        loginout.setLogoutTime(EGTimeFormatUtil.parseGMT8("20" + collectTime).getTime());
        
        loginout.setCallLetter(callLetter);

        logger_debug.debug("[EG][Cmd04][" + callLetter + "]recv login out info:" + loginout);
        session.close();
        try {
            TransferDeviceManager.instance.clientLogout(callLetter);
        } catch (Exception e) {
            LogManager.t(e.getMessage(), e);
        }
		return true;
	}
}